package com.loong.loong.hik.service;

import com.alibaba.nacos.common.utils.StringUtils;
import com.loong.loong.hik.property.request.card.CardAppointmentCancelRequest;
import com.loong.loong.hik.property.request.card.CardAppointmentRegistrationRequest;
import com.loong.loong.hik.property.request.card.CardAuthConfigAddRequest;
import com.loong.loong.hik.property.request.card.CardAuthDownloadRequest;
import com.loong.loong.hik.property.request.card.CardAuthQcodeRequest;
import com.loong.loong.hik.property.request.card.CardAuthReapplicationRequest;
import com.loong.loong.hik.property.request.card.CardAuthdownloadDataRequest;
import com.loong.loong.hik.property.request.card.CardAuthdownloadDiyRequest;
import com.loong.loong.hik.property.request.card.CardBlacklistPersonRequest;
import com.loong.loong.hik.property.request.card.CardPrivilegeGroupRequest;
import com.loong.loong.hik.property.request.card.CardSimpleDownloadRequest;
import com.loong.loong.hik.property.request.card.CardTaskAdditionRequest;
import com.loong.loong.hik.property.request.card.CardVisitingRecordsRequest;
import com.loong.loong.hik.property.request.door.AcsdeviceSearchRequest;
import com.loong.loong.hik.property.request.door.DoorControlRequest;
import com.loong.loong.hik.property.request.door.DoorSearchRequest;
import com.loong.loong.hik.property.request.door.ReaderSearchRequest;
import com.loong.loong.hik.property.result.card.CardAppointmentCancelResult;
import com.loong.loong.hik.property.result.card.CardAppointmentRegistrationResult;
import com.loong.loong.hik.property.result.card.CardAuthConfigAddResult;
import com.loong.loong.hik.property.result.card.CardAuthDownloadResult;
import com.loong.loong.hik.property.result.card.CardAuthQcodeResult;
import com.loong.loong.hik.property.result.card.CardAuthReapplicationResult;
import com.loong.loong.hik.property.result.card.CardAuthdownloadDataResult;
import com.loong.loong.hik.property.result.card.CardAuthdownloadDiyResult;
import com.loong.loong.hik.property.result.card.CardBlacklistPersonResult;
import com.loong.loong.hik.property.result.card.CardPrivilegeGroupResult;
import com.loong.loong.hik.property.result.card.CardSimpleDownloadResult;
import com.loong.loong.hik.property.result.card.CardTaskAdditionResult;
import com.loong.loong.hik.property.result.card.CardVisitingRecordsResult;
import com.loong.loong.hik.property.result.card.CardVisitorinfoFieldResult;
import com.loong.loong.hik.property.result.door.AcsdeviceSearchResult;
import com.loong.loong.hik.property.result.door.DoorControlResult;
import com.loong.loong.hik.property.result.door.DoorSearchResult;
import com.loong.loong.hik.property.result.door.ReaderSearchResult;
import com.loong.loong.hik.property.urls.card.HikCardUrl;
import com.loong.loong.hik.util.HikUtil;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * 一卡通
 * @author jinyiang
 * @date 2023/3/12 14:45
 */
@Component
public class HikOneCardVService {

	@Resource
	private HikUtil hikUtil;
	/**
	 * 按人员详情与设备下发
	 */
	public CardAuthDownloadResult authDownload(CardAuthDownloadRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.AUTHDOWNLOAD, videoPrivilegeGroupRequest, CardAuthDownloadResult.class);
	}
	/**
	 * 查询按人员详情与设备下发信息
	 */
	public CardAuthdownloadDiyResult authdownloadDiy(CardAuthdownloadDiyRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.AUTHDOWNLOAD_DIY, videoPrivilegeGroupRequest, CardAuthdownloadDiyResult.class);
	}
	/**
	 * 创建下载任务_根据人员与设备通道指定下载
	 */
	public CardTaskAdditionResult taskAddition(CardTaskAdditionRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.TASK_ADDITION, videoPrivilegeGroupRequest, CardTaskAdditionResult.class);
	}
	/**
	 * 下载任务中添加数据_根据人员与设备通道指定下载
	 */
	public CardAuthdownloadDataResult authdownloadData(CardAuthdownloadDataRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.AUTHDOWNLOAD_DATA, videoPrivilegeGroupRequest, CardAuthdownloadDataResult.class);
	}
	/**
	 * 简单同步权限下载_根据人员与设备通道指定下载
	 */
	public CardSimpleDownloadResult simpleDownload(CardSimpleDownloadRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.SIMPLEDOWNLOAD, videoPrivilegeGroupRequest, CardSimpleDownloadResult.class);
	}
	/**
	 * 添加权限配置
	 */
	public CardAuthConfigAddResult authConfigAdd(CardAuthConfigAddRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.AUTH_CONFIG_ADD, videoPrivilegeGroupRequest, CardAuthConfigAddResult.class);
	}
	/**
	 * 查询访客权限组 PRIVILEGE_GROUP
	 */
	public CardPrivilegeGroupResult privilegeGroup(CardPrivilegeGroupRequest videoPrivilegeGroupRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.PRIVILEGE_GROUP, videoPrivilegeGroupRequest, CardPrivilegeGroupResult.class);
	}
	/**
	 * 获取访客基础信息字段
	 */
	public CardVisitorinfoFieldResult visitorinfoField() throws Exception{
		return hikUtil.doPost(HikCardUrl.VISITORINFO_FIELD, null, CardVisitorinfoFieldResult.class);
	}

	/**
	 * 查询访客来访记录v2
	 */
	public CardVisitingRecordsResult visitingRecords(CardVisitingRecordsRequest videoVisitingRecordsRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.VISITING_RECORDS, videoVisitingRecordsRequest, CardVisitingRecordsResult.class);
	}
	/**
	 * 预约免登记
	 */
	public CardAppointmentRegistrationResult appointmentRegistration(CardAppointmentRegistrationRequest videoVisitingRecordsRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.VISITOR_APPOINTMENT_REGISTRATION, videoVisitingRecordsRequest, CardAppointmentRegistrationResult.class);
	}
	/**
	 * 访客权限重新下发
	 */
	public CardAuthReapplicationResult authReapplication(CardAuthReapplicationRequest videoAuthReapplicationRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.AUTH_REAPPLICATION, videoAuthReapplicationRequest, CardAuthReapplicationResult.class);
	}
	/**
	 * 取消访客预约
	 */
	public CardAppointmentCancelResult appointmentCancel(CardAppointmentCancelRequest videoAppointmentCancelRequest) throws Exception{
		if (videoAppointmentCancelRequest!=null&& StringUtils.isNotEmpty(videoAppointmentCancelRequest.getAppointmentId())){
			List arraryList = new ArrayList();
			arraryList.add(videoAppointmentCancelRequest.getAppointmentId());
			return hikUtil.doPost(HikCardUrl.VISITOR_APPOINTMENT_CANCEL, arraryList, CardAppointmentCancelResult.class);
		}else{
			return null;
		}

	}
	//AUTH_QCODE
	/**
	 * 生成访客动态二维码内容
	 */
	public CardAuthQcodeResult authQcode(CardAuthQcodeRequest cardAuthQcodeRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.AUTH_QCODE, cardAuthQcodeRequest, CardAuthQcodeResult.class);
	}
	//AUTH_QCODE
	/**
	 * 访客黑名单分组中配置人员数据
	 */
	public CardBlacklistPersonResult blacklistPerson(CardBlacklistPersonRequest cardBlacklistPersonRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.BLACKLIST_PERSON_SET, cardBlacklistPersonRequest, CardBlacklistPersonResult.class);
	}
	/**
	 * 门禁点反控
	 */
	public DoorControlResult doorControl(DoorControlRequest doorControlRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.BLACKLIST_PERSON_SET, doorControlRequest, DoorControlResult.class);
	}
	/**
	 * 查询门禁点列表
	 */
	public DoorSearchResult doorSearch(DoorSearchRequest doorSearchRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.DOOR_SEARCH, doorSearchRequest, DoorSearchResult.class);
	}
	/**
	 * 查询门禁设备列表
	 */
	public AcsdeviceSearchResult acsdeviceSearch(AcsdeviceSearchRequest acsdeviceSearchRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.ACSDEVICE_SEARCH, acsdeviceSearchRequest, AcsdeviceSearchResult.class);
	}
	/**
	 * 查询门禁设备列表
	 */
	public ReaderSearchResult readerSearch(ReaderSearchRequest readerSearchRequest) throws Exception{
		return hikUtil.doPost(HikCardUrl.ACSDEVICE_SEARCH, readerSearchRequest, ReaderSearchResult.class);
	}




}
